using System;
using System.Collections.Generic;
using System.Text;
using Impact.Model.Service;
using StructureMap;

namespace Impact.Model.Objects
{
    public partial class TagCollection
    {

        /// <summary>
        /// constructor converts parameter into Tags added to the new collection
        /// </summary>
        public TagCollection(IEnumerable<string> tags)
        {
            if (tags != null)
            {
                ITagService tagService = ObjectFactory.GetInstance<ITagService>();
                foreach (string tagText in tags)
                {
                    Tag t = tagService.FetchByText(tagText.Trim());
                    t.Text = tagText.Trim();
                    this.Add(t);
                }
            }
        }

        /// <summary>
        /// Saves all the tags in the collection
        /// </summary>
        /// <param name="userId">userID initiating the save operation</param>
        public void Save(Guid userId)
        {
            foreach (Tag t in this)
            {
                t.Save(userId);
            }
        }

    }
}
